import {
    Column,
    Entity,
    JoinColumn,
    OneToOne,
    PrimaryGeneratedColumn,
} from 'typeorm'
import { User } from './User'

@Entity({
    name: 'id_card',
})
export class IdCard {
    @PrimaryGeneratedColumn()
    id: number

    @Column({
        length: 50,
        comment: '身份证号',
    })
    cardName: string

    // 添加外键列
    @JoinColumn()
    @OneToOne(() => User, {
        // 增删改entity时, 是否增删关联的entity
        cascade: true,
        // 修改级联关系, 默认 RESTRICT
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    })
    user: User
}
